package converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import user.Role;

/**
 *
 * @author Thorsten Ludwig
 */
@FacesConverter(value="roleConverter", forClass=Role.class)
public class RoleConverter implements Converter {

    
    @Override
    public Object getAsObject(FacesContext fc, UIComponent uic, String string) {
        if (string.equalsIgnoreCase("Admin")) 
            return Role.ADMIN;
        else if (string.equalsIgnoreCase("Coadmin"))
            return Role.COADMIN;
        else if (string.equalsIgnoreCase("Student"))
            return Role.STUDENT;
        else if (string.equalsIgnoreCase("Tutor"))
            return Role.TUTOR;
        else 
            return Role.GUEST;
    }

    @Override
    public String getAsString(FacesContext fc, UIComponent uic, Object o) {
        return o.toString();
    }
    
}
